package com.rc.saas.tenant.controller.ugs;

import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.BaseSearch;
import com.rc.saas.tenant.base.WebPageInfo;
import com.rc.saas.tenant.mapper.ugs.TenantUgsLevelTypeMapper;
import com.rc.saas.tenant.model.tenant.TenantUser;
import com.rc.saas.tenant.model.ugs.TenantUgsLevelType;
import com.rc.saas.tenant.model.ugs.TenantUgsLevelTypeExample;
import com.rc.saas.tenant.search.tenant.TenantUgsMemberLevelSearch;
import com.rc.saas.tenant.service.ugs.TenantUgsMemberLevelService;
import com.rc.saas.tenant.service.ugs.UgsMemberLevelRecordService;
import com.rc.saas.tenant.shiro.ShiroUtils;
import com.rc.saas.tenant.vo.ugs.TenantUgsMemberLevelResultVo;
import com.rc.saas.tenant.vo.ugs.UgsMemberLevelRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author frog
 * @date 2021/4/8
 */
@Controller
@RequestMapping("/tenantUgsMemberLevel")
public class TenantUgsMemberLevelController {

    @Autowired
    private TenantUgsMemberLevelService tenantUgsMemberLevelService;


    @Autowired
    private UgsMemberLevelRecordService ugsMemberLevelRecordService;

    @Autowired
    private TenantUgsLevelTypeMapper tenantUgsLevelTypeMapper;

    /**
     * 跳转会员等级 页面
     */
    @RequestMapping("/index")
    public String tenantUgsMemberLevelPage(Model model) {
        TenantUser sessionUser = ShiroUtils.getSessionUser();
        TenantUgsLevelTypeExample example = new TenantUgsLevelTypeExample();
        example.createCriteria().andTenantCodeEqualTo(sessionUser.getTenantCode());
        List<TenantUgsLevelType> tenantUgsLevelTypes = tenantUgsLevelTypeMapper.selectByExample(example);
        model.addAttribute("tenantUgsLevelTypes", tenantUgsLevelTypes);
        return "/templates/ugs/tenantUgsMemberLevel";
    }

    /**
     * 查询会员等级记录
     *
     * @return
     */
    @RequestMapping("/listPageTenantUgsMemberLevel")
    @ResponseBody
    public WebPageInfo listPageTenantUgsMemberLevel(TenantUgsMemberLevelSearch tenantUgsMemberLevelSearch) {
        PageInfo<TenantUgsMemberLevelResultVo> pageInfo = tenantUgsMemberLevelService.listPageTenantUgsMemberLevel(tenantUgsMemberLevelSearch);
        WebPageInfo webPageInfo = new WebPageInfo(pageInfo.getList(), Long.valueOf(pageInfo.getTotal()).intValue());
        return webPageInfo;
    }


    /**
     * 跳转成长值记录 页面
     */
    @RequestMapping("/memberLevelRecord/{memberId}")
    public String memberLevelRecord(@PathVariable("memberId") Long memberId, Model model) {
        model.addAttribute("memberId", memberId);
        return "/templates/ugs/memberLevelRecord";
    }

    /**
     * 查询成长值记录列表
     *
     * @return
     */
    @RequestMapping(value = "/listPageMemberLevelRecord", method = RequestMethod.GET)
    @ResponseBody
    public WebPageInfo listPageMemberLevelRecord(BaseSearch baseParam, Long memberId) {
        PageInfo<UgsMemberLevelRecordVo> pageInfo = ugsMemberLevelRecordService.listPageMemberLevelRecord(baseParam, memberId);
        WebPageInfo webPageInfo = new WebPageInfo(pageInfo.getList(), Long.valueOf(pageInfo.getTotal()).intValue());
        return webPageInfo;
    }


}
